package com.ds.web.ctrl;

import com.ds.api.IOrderDeclaraService;
import com.ds.base.msg.OrderDeclaraMsg;
import com.ds.base.utils.CBTUtil;
import com.ds.persist.vo.http.RespModel;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 订单申报
 * @author zhangyou
 * @date 2018/12/2
 */
@RestController
public class OrderDeclaraCtrl {





    /**
     * 订单申报
     * @param orderDeclaraMsg
     */
    @PostMapping(value = "/order/declara")
    public JSONObject orderDeclara(@Valid @RequestBody OrderDeclaraMsg orderDeclaraMsg,
                                   BindingResult br){
        RespModel respModel = new RespModel();
        if(br.hasErrors()){
            respModel.addError(br);
            return respModel.toJSON();
        }
        JSONObject jsonObject = CBTUtil.sendMsg(orderDeclaraMsg);
        respModel.setData(jsonObject);
        System.out.println(jsonObject.toString());
        //先新增主表
//        orderDeclaraService.doOrderDeclara(orderDeclaraMsg);
        //新增到数据库
        //order_declara
        return respModel.toJSON();
    }








    @Autowired
    private IOrderDeclaraService orderDeclaraService;


}
